package com.example.springboot.mapper;

import com.example.springboot.bean.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

public interface UserMapper {

    @Insert("insert into hyfc_user values(" +
            " default,#{name},#{pwd},#{email},#{head}," +
            " #{phone},default,#{level})")
    @Options(useGeneratedKeys = true,
        keyProperty = "id", keyColumn = "id")
    void insert(User user);

    @Select("select count(*) from hyfc_user where name = #{name}")
    int countByName(String name);


    @Select("select * from hyfc_user" +
            " where name=#{name} and pwd=#{pwd}")
    @Results({
            @Result(property = "id", column = "id", id = true),
            @Result(property = "unreads", column = "id", many = @Many(
                    select = "com.example.springboot.mapper.NotifyMapper.selectByUserId"
            ))
    })
    User selectByLogin(User user);

    @Select("select * from hyfc_user" +
            " where name=#{name}")
    User selectByName(String name);

    @Update("update hyfc_user set pwd=#{pwd} where name=#{name}")
    void updatePwdByName(User user);
}
